package Java_Concurrency_in_Practice.c7_1_6;

import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

public class ReaderThread extends Thread {
    private final Socket socket;
    private final InputStream in;

    public ReaderThread(Socket socket, InputStream in) {
        this.socket = socket;
        this.in = in;
    }

    public void interrupt() {
        try {
            socket.close();
        } catch (IOException ignore) {
        } finally {
            super.interrupt();
        }
    }

    public void run() {
        try {
            byte[] buf = new byte[1024];
            while (true) {
                int len = in.read(buf);
                if (len < 0) {
                    break;
                } else if (len > 0) {
                    // processBuffer(buf, len);
                }
            }
        } catch (IOException e) {
            // 允许线程退出
        }

    }
}
